package com.zpark.se.io.input;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * @PackageName: com.zpark.se.io.input
 * @ClassName: Demo02
 * @Description:
 * @author: RZS
 * @date: 2024/11/19  16:45
 */
public class Demo02 {
    public static void main(String[] args) throws Exception {
        /*
            案例：使用FileInputStream对象读取a.txt文件数据
         */
        String path = "src/com/zpark/se/io/input/f/a.txt";
        // 创建文件输入流对象
        InputStream in = new FileInputStream(path);
        /*
        // 读取数据
        int len = 0;
        // 循环读取
        while ((len = in.read()) != -1) {
            System.out.println((char)len);
        }*/

        // 创建字节数据充当缓冲区
        byte[] data = new byte[8 * 1024];
        int len = 0;
        while ((len = in.read(data)) != -1) {
            // 将读取的数据转换为字符串
            String str = new String(data, 0, len);
            System.out.println(str);
        }

        // 关闭流
        in.close();

    }
}
